package com.lnyt.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class LogUtil {
    private static Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);

    public static Logger log4j2() {
        return logger;
    }

    // 得到当前时间
    public static String getToday() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);

        return dateFormat.format(new Date());
    }

    // 根据输入字符串得到时间
    public static Date parseDateStr(String dateStr, String format) {
        DateFormat dateFormat = new SimpleDateFormat(format, Locale.CHINA);
        Date date = null;

        try {
            date = dateFormat.parse(dateStr);
        } catch (Exception exc) {
            exc.printStackTrace();
        }

        return date;
    }

    // 根据输入时间得到字符串
    public static String formatDate(Date date, String format) {
        DateFormat dateFormat = new SimpleDateFormat(format, Locale.CHINA);
        String result = null;

        try {
            result = dateFormat.format(date);
        } catch (Exception exc) {
            exc.printStackTrace();
        }

        return result;
    }
}
